#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int, int> PII;

vector<PII> a;
int n;

vector<PII> merge(vector<PII> a)
{
    sort(a.begin(), a.end());
    int st = -2e9, ed = -2e9;
    vector<PII> ans;
    for (auto seg : a)
        if (ed < seg.first) //判断后面没有交集
        {
            if (st != -2e9)
                ans.push_back({st, ed}); //不是未定义，就先把此区间丢答案，再转入下一区间
            st = seg.first, ed = seg.second;
        }
        else
            ed = max(ed, seg.second); //拓展此区间

    if (st != -2e9)              //防止数组无区间
        ans.push_back({st, ed}); //把最后一个区间塞进去
    return ans;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        a.push_back({l, r});
    }
    printf("%d", merge(a).size());
    return 0;
}